package com.cy.store.controller;

import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import com.cy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: AngJie
 * @create: 2022-02-09 15:37
 **/
@RestController
@RequestMapping("products")
public class ProductController extends BaseController {

    @Autowired
    private IProductService productService;

    @RequestMapping("hot_product")
    public JsonResult<List<Product>> getHotProduct() {
        List<Product> list = productService.findHotProduct();
        return new JsonResult<>(OK,list);
    }

    //我很奇怪，为什么不使用@PathVariable就取不到参数，我记得同名就可以的
    //2022.04.27 其实是因为@Pathvariable是用来获取路径参数的
    @RequestMapping("details/{id}")
    public JsonResult<Product> getDetails(@PathVariable("id") Integer id) {
        Product result = productService.findById(id);
        return new JsonResult<>(OK,result);
    }
}
